package com.cskaoyan.day1.generic5;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Common-zhou
 * @since 2023-02-27 11:46
 */
public class String2DateConverter implements Converter<String, Date> {
    @Override
    public Date convert(String data) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        Date parse;

        try {
            parse = simpleDateFormat.parse(data);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }

        return parse;
    }

    public static void main(String[] args) {
        String2DateConverter string2DateConverter = new String2DateConverter();

        Date convert = string2DateConverter.convert("2023-02-27");
        System.out.println(convert);
    }
}
